#!/usr/bin/env bash

if [ "${PDNS_TAG}" != 'HEAD' ]
then
    git checkout $PDNS_TAG
    export GIT_BRANCH=unknown
    export GIT_COMMIT=$(git rev-parse $PDNS_TAG)
fi

eval $(build-scripts/make-jenkins-version)

build-scripts/set-version-auth $SOURCE_VERSION $DEB_VERSION $RPM_VERSION
build-scripts/set-version-recursor $SOURCE_VERSION $DEB_VERSION $RPM_VERSION

if [ "${JENKINS_URL}" = "https://autotest.powerdns.com/" ]
then
    JENKINS_URL=http://localhost:8080/
fi

if [ -n "${JENKINS_URL}" ]
then
    DESC="#${BUILD_NUMBER} [${GIT_BRANCH#origin/} $(git rev-parse --short $GIT_COMMIT)]"
    if [ "${PDNS_TAG}" != 'HEAD' ]
    then
        DESC="${DESC} (${PDNS_TAG})"
    fi
    java -jar /shared/jenkins-cli.jar set-build-display-name ${JOB_NAME} ${BUILD_NUMBER} "${DESC}"
fi
